package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	numbers, err := GetFloat("../data.txt")
	if err != nil {
		log.Fatal(err)
	}
	var sum float64
	for _, number := range numbers {
		sum += number
	}
	sampleCount := float64(len(numbers))
	fmt.Printf("Average: %0.2f\n", sum/sampleCount)
}

func GetFloat(filename string) (numbers [3]float64, err error) {
	var number [3]float64
	file, err := os.Open(filename)
	if err != nil {
		return number, err
	}
	scanner := bufio.NewScanner(file)
	for i := 0; scanner.Scan(); i++ {
		number[i], err = strconv.ParseFloat(scanner.Text(), 64)
	}
	err = file.Close()
	if err != nil {
		return number, err
	}
	if scanner.Err() != nil {
		return number, scanner.Err()
	}
	return number, err
}
